package com.personal.controller;

import com.personal.bo.ShopCartBO;
import com.personal.service.ShopCartService;
import com.personal.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shopCart")
@Api(tags = "购物车功能模块",value = "shopCartController控制层")
public class ShopCartController {

    @Autowired
    private ShopCartService shopCartService;

    @PostMapping("/addCart")
    @ApiOperation("添加进购物车")
    public Result addCart(@RequestBody ShopCartBO shopCartBO){
        return shopCartService.addCart(shopCartBO);
    }

    @GetMapping("/getUserShopCartList")
    @ApiOperation("获取我的购物车列表")
    public Result getUserShopCartList(@RequestParam("userId") Integer userId){
        return shopCartService.getUserShopCartList(userId);
    }

    @DeleteMapping("/clearUserShopCartList")
    @ApiOperation("清空购物车")
    public Result clearUserShopCartList(@RequestParam("userId") Integer userId){
        return shopCartService.clearUserShopCartList(userId);
    }

    @DeleteMapping("/deleteShopCartByResourcesId")
    @ApiOperation("根据商品id删除购物车中的该商品")
    public Result deleteShopCartByResourcesId(@RequestParam("resourcesId") Integer resourcesId,
                                              @RequestParam("userId") Integer userId) {
        return shopCartService.deleteShopCartByResourcesId(resourcesId,userId);
    }

}
